package com.sky.codeGenerate.modules.userInfo.service;

import com.sky.common.basic.BaseService;
import java.util.List;
import java.util.Collections;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import com.github.pagehelper.PageInfo;
import cn.hutool.core.bean.BeanUtil;

import com.sky.codeGenerate.modules.userInfo.entity.UserInfo;
import com.sky.codeGenerate.modules.userInfo.entity.UserInfoParam;
import com.sky.codeGenerate.modules.userInfo.entity.UserInfoVO;
import com.sky.codeGenerate.modules.userInfo.mapper.UserInfoMapper;


@Slf4j
@Service
public class UserInfoService extends BaseService {

	@Autowired
	private UserInfoMapper userInfoMapper;

    /** 查询列表(分页) **/
    public PageInfo<UserInfoVO> getUserInfoPage(UserInfoParam param){
		param.enablePage();
		return toPageInfo(userInfoMapper.findList(param),UserInfoVO.class);
	}

    /** 查询列表 **/
    public List<UserInfoVO> getUserInfoList(UserInfoParam param) {
		 return copyToList(userInfoMapper.findList(param), UserInfoVO.class);
	}

    /** 根据ID获取详情 **/
    public UserInfoVO getUserInfoById(Integer id) {
		return BeanUtil.toBean(userInfoMapper.findById(id), UserInfoVO.class);
	}

    /** 新增 **/
    public Integer insertUserInfo(UserInfo userInfo) {
		return insertBatchUserInfo(Collections.singletonList(userInfo));
	}

    /** 批量新增 **/
    public Integer insertBatchUserInfo(List<UserInfo> userInfoList) {
		return userInfoMapper.insertBatch(userInfoList);
	}

    /** 更新 **/
    @Transactional
    public Integer updateUserInfo(UserInfo userInfo) {
		  return updateBatchUserInfo(Collections.singletonList(userInfo));
	}

    /** 批量更新 **/
    public Integer updateBatchUserInfo(List<UserInfo> userInfoList) {
		  return userInfoMapper.updateBatch(userInfoList);
	}

    /** 根据ID删除 **/
    public Integer delUserInfoById(Integer id) {
	  return delUserInfoByIds(Collections.singletonList(id));
	}

    /** 根据ID批量删除 **/
    public Integer delUserInfoByIds(List<Integer> ids) {
		return userInfoMapper.delByIds(ids);
	}

}